package com.qing.springbootinit.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qing.qingapicommon.model.entity.InterfaceInfo;
import com.qing.qingapicommon.service.InnerInterfaceInfoService;
import com.qing.springbootinit.common.ErrorCode;
import com.qing.springbootinit.exception.BusinessException;
import com.qing.springbootinit.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

// * @author qingfengzy

@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {
    /**
     * 从数据库中查询模拟接口是否存在（请求路径、请求方法、请求参数）
     */

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {

//        然后如何知道方法是否存在呢？
//        就要获取他的url路径和方法名
        if(StringUtils.isAnyBlank(url,method)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
//        然后就靠这两个参数搜索
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url",url);
        queryWrapper.eq("method",method);
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
